home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / NetTimestamp.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  3.9 KB  |  141 lines

  1. package symantec.itools.db.net;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.IOException;
  6. import symjava.sql.Date;
  7. import symjava.sql.SQLException;
  8. import symjava.sql.Time;
  9. import symjava.sql.Timestamp;
  10.  
  11. class NetTimestamp extends DateTimeField {
  12.    Timestamp _tsVal;
  13.  
  14.    int getType() {
  15.       return 77;
  16.    }
  17.  
  18.    void readData(DataInputStream is) throws SQLException, IOException, ErrorException {
  19.       int iYear = 0;
  20.       ServerObject obj = (ServerObject)NetClass.getNextObject(is);
  21.       if (obj.getType() == 51) {
  22.          iYear = ((NetData)obj).getInt();
  23.       } else {
  24.          ((ServerObject)this).onObjectError(obj);
  25.       }
  26.  
  27.       int iMonth = 0;
  28.       obj = (ServerObject)NetClass.getNextObject(is);
  29.       if (obj.getType() == 51) {
  30.          iMonth = ((NetData)obj).getInt();
  31.       } else {
  32.          ((ServerObject)this).onObjectError(obj);
  33.       }
  34.  
  35.       int iDay = 0;
  36.       obj = (ServerObject)NetClass.getNextObject(is);
  37.       if (obj.getType() == 51) {
  38.          iDay = ((NetData)obj).getInt();
  39.       } else {
  40.          ((ServerObject)this).onObjectError(obj);
  41.       }
  42.  
  43.       int iHour = 0;
  44.       obj = (ServerObject)NetClass.getNextObject(is);
  45.       if (obj.getType() == 51) {
  46.          iHour = ((NetData)obj).getInt();
  47.       } else {
  48.          ((ServerObject)this).onObjectError(obj);
  49.       }
  50.  
  51.       int iMinutes = 0;
  52.       obj = (ServerObject)NetClass.getNextObject(is);
  53.       if (obj.getType() == 51) {
  54.          iMinutes = ((NetData)obj).getInt();
  55.       } else {
  56.          ((ServerObject)this).onObjectError(obj);
  57.       }
  58.  
  59.       int iSeconds = 0;
  60.       obj = (ServerObject)NetClass.getNextObject(is);
  61.       if (obj.getType() == 51) {
  62.          iSeconds = ((NetData)obj).getInt();
  63.       } else {
  64.          ((ServerObject)this).onObjectError(obj);
  65.       }
  66.  
  67.       int iNanoSeconds = 0;
  68.       obj = (ServerObject)NetClass.getNextObject(is);
  69.       if (obj.getType() == 51) {
  70.          iNanoSeconds = ((NetData)obj).getInt();
  71.       } else {
  72.          ((ServerObject)this).onObjectError(obj);
  73.       }
  74.  
  75.       if (!super._null) {
  76.          try {
  77.             this._tsVal = new Timestamp(iYear, iMonth - 1, iDay, iHour, iMinutes, iSeconds, iNanoSeconds);
  78.          } catch (IllegalArgumentException var10) {
  79.             this._tsVal = null;
  80.          }
  81.       } else {
  82.          this._tsVal = null;
  83.       }
  84.    }
  85.  
  86.    void writeData(DataOutputStream os) throws IOException {
  87.       NetData data = new NetData((short)this._tsVal.getYear());
  88.       data.write(os);
  89.       data = new NetData((short)this._tsVal.getMonth());
  90.       data.write(os);
  91.       data = new NetData((short)this._tsVal.getDate());
  92.       data.write(os);
  93.       data = new NetData((short)this._tsVal.getHours());
  94.       data.write(os);
  95.       data = new NetData((short)this._tsVal.getMinutes());
  96.       data.write(os);
  97.       data = new NetData((short)this._tsVal.getSeconds());
  98.       data.write(os);
  99.       data = new NetData((short)this._tsVal.getNanos());
  100.       data.write(os);
  101.    }
  102.  
  103.    public String getString() throws SQLException {
  104.       return ((Field)this).isNull() ? null : this._tsVal.toString();
  105.    }
  106.  
  107.    public Date getDate() throws SQLException {
  108.       return ((Field)this).isNull() ? null : new Date(this._tsVal.getYear(), this._tsVal.getMonth(), this._tsVal.getDate());
  109.    }
  110.  
  111.    public Time getTime() throws SQLException {
  112.       return ((Field)this).isNull() ? null : new Time(this._tsVal.getHours(), this._tsVal.getMinutes(), this._tsVal.getSeconds());
  113.    }
  114.  
  115.    public Timestamp getTimestamp() throws SQLException {
  116.       return ((Field)this).isNull() ? null : this._tsVal;
  117.    }
  118.  
  119.    public int getSQLType() {
  120.       return 93;
  121.    }
  122.  
  123.    public Object getObject() throws SQLException {
  124.       return new Timestamp(this._tsVal.getYear(), this._tsVal.getMonth(), this._tsVal.getDate(), this._tsVal.getHours(), this._tsVal.getMinutes(), this._tsVal.getSeconds(), this._tsVal.getNanos());
  125.    }
  126.  
  127.    public void setObject(Object obj) throws SQLException {
  128.       this.setTimestamp((Timestamp)obj);
  129.    }
  130.  
  131.    public void setString(String x) throws SQLException {
  132.       this._tsVal = Timestamp.valueOf(x);
  133.       super._null = false;
  134.    }
  135.  
  136.    public void setTimestamp(Timestamp x) throws SQLException {
  137.       this._tsVal = x;
  138.       super._null = false;
  139.    }
  140. }
  141.